<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-main>
                <el-form :model="form" :rules="rules" ref="dialogForm" label-width="110px" label-position="right" style="height:200px;overflow:auto">
                    <!-- <sc-editor :disabled="mode=='show'" v-model="form.reason_id" placeholder="请输入" :height="350"></sc-editor> -->
                    <el-form-item label="付款金额" prop="money">
                        <el-input v-model="form.money" placeholder="请输入付款金额" clearable autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark" placeholder="请输入备注" clearable autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
            </el-main>
            <el-footer>
                <div style="display:flex;justify-content: end;">
                    <el-button @click="visible=false" >取 消</el-button>
			        <el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
                </div>
            </el-footer>
        </el-container>
	</el-dialog>
</template>

<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '添加客户',
					edit: '编辑客户',
					over: '付款'
				},
				visible: false,
				isSaveing: false,
                grade:"潜力",
				//表单数据
				form: {
                    id:"",
					money:"",
                    remark:"",
				},
				//验证规则
				rules: {
                    money: [
						{required: true, message: '请输入金额'}
					],
                },
                returnList:[],
			}
		},
		mounted() {
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						this.isSaveing = true;
						var res  = [];
						res = await this.$API.inventory.payment.post(this.form);
						this.isSaveing = false;
						if(res.code == 1){
							this.$emit('success', this.form, this.mode)
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}else{
						return false;
					}
				})
			},
			//表单注入数据
			setData(data){
                this.form.id = data.id
                this.form.money = data.meet_money
			},
		}
	}
</script>

<style lang="scss">
.el-form-item--default{
    align-items: center;
}
</style>
